﻿Imports System.Data.SqlClient
Public Class clsOperadoresGlobal
    Private mintIdOperador As Integer
    Private mintIdEmpleado As Integer
    Private mstrCodigo As String
    Private mstrNombre As String
    Private mstrEstadoEmpleado As String
    Private mstrEmpresa As String
    Public Property IdOperador() As Integer
        Get
            Return mintIdOperador
        End Get
        Set(ByVal value As Integer)
            mintIdOperador = value
        End Set
    End Property
    Public Property IDEmpleado() As Integer
        Get
            Return mintIdEmpleado
        End Get
        Set(ByVal value As Integer)
            mintIdEmpleado = value
        End Set
    End Property
   
    Public Property Codigo() As String
        Get
            Return mstrCodigo
        End Get
        Set(ByVal value As String)
            mstrCodigo = value
        End Set
    End Property
    Public Property Nombre() As String
        Get
            Return mstrNombre
        End Get
        Set(ByVal value As String)
            mstrNombre = value
        End Set
    End Property
    Public Property EstadoEmpleado() As String
        Get
            Return mstrEstadoEmpleado
        End Get
        Set(ByVal value As String)
            mstrEstadoEmpleado = value
        End Set
    End Property
    Public Property Empresa() As String
        Get
            Return mstrEmpresa
        End Get
        Set(ByVal value As String)
            mstrEmpresa = value
        End Set
    End Property
    Public Sub New()
        mintIdOperador = 0
        mintIdEmpleado = 0
        mstrCodigo = ""
        mstrNombre = ""
        mstrEstadoEmpleado = ""
        mstrEmpresa = ""
        
    End Sub
    Public Sub Insertar()
        Dim sql As String = "Insert Into OperadoresGlobal (" & _
                            "IdEmpleado," & _
                            "Codigo," & _
                            "Nombre," & _
                            "EstadoEmpleado," & _
                            "Empresa) " & _
                            "VALUES (" & _
                            "@IdEmpleado," & _
                            "@Codigo," & _
                            "@Nombre," & _
                            "@EstadoEmpleado," & _
                            "@Empresa)"

        Dim cnConn As New SqlConnection
        cnConn.ConnectionString = CitraConnection

        Dim Command As New SqlCommand(sql, cnConn)

        Command.Parameters.AddWithValue("IdEmpleado", mintIdEmpleado)
        Command.Parameters.AddWithValue("Codigo", mstrCodigo)
        Command.Parameters.AddWithValue("Nombre", mstrNombre)
        Command.Parameters.AddWithValue("EstadoEmpleado", mstrEstadoEmpleado)
        Command.Parameters.AddWithValue("Empresa", mstrEmpresa)
        

        cnConn.Open()
        Dim RowsAffected As Integer
        Try
            RowsAffected = Command.ExecuteNonQuery
        Catch ex As Exception
            MsgBox(ex.Message, MsgBoxStyle.Exclamation, "Aviso")
        End Try

        If RowsAffected > 0 Then
            cnConn.Close()
        Else
            MsgBox("No fue posible insertar el Empleado ", MsgBoxStyle.Exclamation, "Aviso")
            If cnConn.State = ConnectionState.Open Then
                cnConn.Close()
            End If
        End If
    End Sub
    Sub Actualizar()
        Dim strSqlQry As String
        Dim cnConn As New SqlConnection
        cnConn.ConnectionString = CitraConnection

        strSqlQry = "Update OperadoresGlobal Set " & _
                            "IdEmpleado=@IdEmpleado," & _
                            "Codigo=@Codigo," & _
                            "Nombre=@Nombre," & _
                            "EstadoEmpleado=substring(@EstadoEmpleado,1,1)," & _
                            "Empresa=@Empresa " & _
                            " where IdOperador=@IdOperador"


        Dim Command As New SqlCommand(strSqlQry, cnConn)
       Command.Parameters.AddWithValue("IdOperador", mintIdOperador)
        Command.Parameters.AddWithValue("IdEmpleado", mintIdEmpleado)
        Command.Parameters.AddWithValue("Codigo", mstrCodigo)
        Command.Parameters.AddWithValue("Nombre", mstrNombre)
        Command.Parameters.AddWithValue("EstadoEmpleado", mstrEstadoEmpleado)
        Command.Parameters.AddWithValue("Empresa", mstrEmpresa)

        cnConn.Open()

        Dim RowsAffected As Integer = Command.ExecuteNonQuery

        If RowsAffected > 0 Then
            cnConn.Close()
        Else
            MsgBox("No fue posible actualizar el registro", MsgBoxStyle.Exclamation, "Aviso")
            If cnConn.State = ConnectionState.Open Then
                cnConn.Close()
            End If
        End If

    End Sub
End Class
